package co.com.test.controller;

import java.io.File;
import java.net.URI;
import java.util.List;

import junit.framework.TestCase;
import co.com.jtune.controller.LibraryController;
import co.com.jtune.controller.implementations.LibraryControllerImpl;
import co.com.jtune.model.TrackModel;
import co.com.jtune.persistence.localPersistence.LocalPersistenceTrackImpl;
import co.com.test.JTuneTestSuite;

/**
 * Prueba todos los servicios del controller {@link LibraryController}
 *
 * @author agutierrez
 *
 */
public class LibraryControllerTestCase extends TestCase{
	
	
	/**
	 * Retorna la libreria
	 * @return
	 */
	public void testGetLibrary() throws Exception
	{

		LibraryController libraryController = new LibraryControllerImpl(LocalPersistenceTrackImpl.getTrackPersistenceInstance(JTuneTestSuite.perference));
		
		List<TrackModel> tracks = libraryController.getLibrary();
		
		assertNotNull(tracks);
	}
	
	/**
	 * Agrega un archivo a la libreria
	 * @param file
	 */
	public void testAddTrackToLibrary() throws Exception
	{
		LibraryController libraryController = new LibraryControllerImpl(LocalPersistenceTrackImpl.getTrackPersistenceInstance(JTuneTestSuite.perference));
		
		int tracksBefore = libraryController.getLibrary().size();
		
		File file = new File("../JTune/tracks/01 All You Need Is Love.mp3");
		
		libraryController.addTrackToLibrary(file);
		int tracksAfter = libraryController.getLibrary().size();
		
		assertTrue(tracksBefore < tracksAfter);
		
	}
//	public void testWhen3tracksBeforeThenAdd1MoreTrackShouldHave4tracks() throws Exception
//	public void testWhen0tracksThenAdd1TrackShouldHave1track() throws Exception

	/**
	 * Agrega una lista de archivos a la libreria
	 * @param file
	 */
	public void testAddTrackListToLibrary()
	{
		LibraryController libraryController = new LibraryControllerImpl(LocalPersistenceTrackImpl.getTrackPersistenceInstance(JTuneTestSuite.perference));
		
		int filesToInsert = 3;
		int tracksBefore = libraryController.getLibrary().size();
		
		File[] files = new File[filesToInsert];
		
		for (int i = 0; i < filesToInsert; i++) {
			files[i] = new File("../JTune/tracks/01 All You Need Is Love.mp3");
		}
		
		
		libraryController.addTrackListToLibrary(files);
		
		int tracksAfter = libraryController.getLibrary().size();
		
		assertTrue(tracksAfter - tracksBefore == filesToInsert);
//		assertEquals(3, tracksAfter + tracksBefore);
	}
	
	public void testShowFail()
	{
		assertTrue("Este test siempre falla", false);
	}

}
